import { createStore } from 'vuex';

export default createStore({
  state: {
    elements: [],
    selectedElement: null
  },
  mutations: {
    addElement(state, element) {
      state.elements.push(element);
    },
    updateElement(state, { id, properties }) {
      const index = state.elements.findIndex(el => el.id === id);
      if (index !== -1) {
        state.elements[index] = { ...state.elements[index], ...properties };
        if (state.selectedElement && state.selectedElement.id === id) {
          state.selectedElement = { ...state.elements[index] };
        }
      }
    },
    removeElement(state, id) {
      state.elements = state.elements.filter(el => el.id !== id);
    },
    selectElement(state, element) {
      state.selectedElement = element;
    }

  },
  actions: {

  },
  getters: {
  }
});
